package org.jslaughter.component.pickup;

import org.jslaughter.component.inventory.WeaponManager;
import org.nvframe.entity.Entity;
import org.nvframe.exception.NVFrameException;
import org.nvframe.exception.NVFrameRuntimeException;
import org.nvframe.manager.ConfigManager;
import org.nvframe.util.settings.SettingsObj;

public class WeaponPickup extends AbstractPickup {
	
	private String weaponId;

	public WeaponPickup(String id, Entity owner, SettingsObj settings)
			throws NVFrameException {
		super(id, owner, settings);
		
		weaponId = settings.getString("weaponId", null);
		
		if(weaponId == null)
			throw new NVFrameException("cannot initialize WeaponPickup with weaponId = null");
	}

	/**
	 * Add the weapon to the weaponmanager of the receiver
	 * 
	 * @param entity The Entity who receives the pickup
	 */
	public boolean pickupAction(Entity receiver) {
		if(ConfigManager.getInstance().getActive("debugMode"))
			System.out.println("pick-up - type: weapon | receiver: "+ receiver.getId() + " | weaponId: " + weaponId);
		
		// retreive weaponmanager from receiver
		WeaponManager manager = (WeaponManager) receiver.getComponent(WeaponManager.class);
		
		if(manager == null)
			throw new NVFrameRuntimeException("pick-up: weapon manager not found for receiver: " + receiver.getId());
		
		manager.addWeapon(weaponId);
		
		return true;
	}

}
